<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
<head>
<title>系统配置管理</title>
<script type="text/javascript">
	var $grid;
	$(function() {
		$grid = $("#grid").datagrid(
				$.extend({}, datagridOption, {
					url : "${ctx}/basic/config/dataGrid",
					columns : [ [
							{
								field : 'ck',
								checkbox : true
							},
							{
								field : 'configNo',
								title : '配置编号',
								width : 140,
								sortable : true
							},
							{
								field : 'configName',
								title : '配置名称',
								width : 140,
								sortable : true
							},
							{
								field : 'configValue',
								title : '配置值',
								width : 140,
								sortable : true
							},
							{
								field : 'remark',
								title : '备注',
								width : 140,
								sortable : true
							},
							{
								field : 'enable',
								title : '是否启用',
								width : 100,
								formatter : function(value, row, index) {
									return '<input class="easyui-switchbutton" ' + (value == 1 ? "checked" : "")
											+ ' data-options="readonly:true,onText:\'是\',offText:\'否\'">';
								}
							} ] ],
					onDblClickRow : function(index, rowData) {
						$.isFunction(fn_edit) && fn_edit.call(this, rowData);
					}
				}));

		$grid.datagrid('enableFilter', [ buildDGFilterYesOrNoFieldOptions($grid, 'enable') ]);
		
		$("#enableSB").switchbutton({
			onText : "是",
			offText : "否",
			checked : true,
			onChange : function(checked) {
				if (checked) {
					$("#enable").val(1);
				} else {
					$("#enable").val(2);
				}
			}
		});
		$("#add").click(function() {
			$("#fm").form("clear");
			$('#fm').form('load', {
				enable : 1
			});
			$("#enableSB").switchbutton('check');
			$("#dlg").dialog("open").dialog("setTitle", "新增系统配置");
		});
		$("#edit").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (!rowData) {
				showInfo("您未选中行，无法编辑");
			} else {
				fn_edit(rowData);
			}
		});
		$("#delete").click(function() {
			multiDeleteDataGrid($grid, "${ctx}/basic/config/multiDelete");
		});
		$("#search").click(function() {
			$grid.datagrid('load', $("#tt").form("getData"));
		});

		$("#flush").click(function() {
			$.get("${ctx}/basic/config/flush", function(data) {
				showInfoForCallBack(data);
			}, "json");
		});

		$("#excelImport").click(function() {
			$.easyui.importor.showImportor({
				importNo : "SystemConfig",
				onExportSuccess : function(file, data) {
					$grid.datagrid('load');
				}
			});
		});
		$("#excelExport").click(function() {
			var url = "${ctx}/basic/config/excelExport?" + $.param($grid.datagrid('options').queryParams);
			if ($grid.datagrid("options").filterRules) {
				url += "&filterRules=" + JSON.stringify($grid.datagrid("options").filterRules);
			}
			window.parent.location.href = url;
		});
		$("#print").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (rowData == null) {
				showInfo("请先选中要打印的行");
			} else {
				window.open("${ctx}/basic/config/print/" + rowData.id, "_blank");
			}
		});
	});
	<shiro:hasPermission name="config:update">
	function fn_edit(rowData) {
		$("#dlg").dialog("open").dialog("setTitle", "编辑系统配置");
		$("#fm").form("clear");
		$("#fm").form("load", rowData);
		$("#enableSB").switchbutton(rowData.enable == 1 ? "check" : "uncheck");
	}
	</shiro:hasPermission>
</script>
</head>

<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="row">
		<div class="col-md-4">
			<form class="form-grid-search form-inline">
				<div class="form-group">
					<input type="text" class="form-control" name="search_LIKE_configName" placeholder="系统配置名称" />
				</div>
				<button type="button" id="search" class="btn btn-primary">
					<span class="glyphicon glyphicon-search"></span> 查询
				</button>
			</form>
		</div>
		<div class="col-md-8">
			<shiro:hasPermission name="config:update">
				<button id="add" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-plus"></span> 新增
				</button>
				<button id="edit" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-pencil"></span> 编辑
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="config:delete">
				<button id="delete" type="button" class="btn btn-danger">
					<span class="glyphicon glyphicon-minus"></span> 删除
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="config:import">
				<button id="excelImport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-open"></span> Excel导入
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="config:export">
				<button id="excelExport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-save"></span> Excel导出
				</button>
			</shiro:hasPermission>
				<button id="print" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-print"></span> 打印
				</button>
			<shiro:hasPermission name="config:print">
			</shiro:hasPermission>
			<button id="flush" type="button" class="btn btn-warning">
				<span class="glyphicon glyphicon-refresh"></span> 清除缓存
			</button>
		</div>
	</div>
	<shiro:hasPermission name="config:update">
		<div id="dlg" class="easyui-dialog" style="width: 370px; height: 350px; padding: 10px 20px"
			data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
			<form id="fm" method="post">
				<input type="hidden" name="id" />
				<table id="tbl">
					<tr>
						<td><label>系统配置编号:</label></td>
						<td><input name="configNo" class="easyui-validatebox" data-options="required: true"></td>
					</tr>
					<tr>
						<td><label>系统配置名称:</label></td>
						<td><input name="configName" class="easyui-validatebox" data-options="required: true"></td>
					</tr>
					<tr>
						<td><label>系统配置值:</label></td>
						<td><input name="configValue" class="easyui-validatebox" data-options="required: true"></td>
					</tr>
					<tr>
						<td><label>是否启用:</label></td>
						<td><input id="enable" name="enable" type="hidden"> <input id="enableSB"></td>
					</tr>
					<tr>
						<td><label>备注:</label></td>
						<td><input name="remark" class="easyui-textbox" data-options="multiline:true,width:185,height:60"></td>
					</tr>
				</table>

			</form>
			<div id="dlg-btn">
				<button id="add" type="button" class="btn btn-primary" onclick="formSave('#fm', '#grid', '#dlg', '${ctx}/basic/config/update');">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
		</div>
	</shiro:hasPermission>
</body>
</html>
